from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-03-28 14:02:19.493389
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Mon, 28, Mar, 2022
Time: 14:02:24
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -48.7279
Nobs: 609.000 HQIC: -49.1263
Log likelihood: 7348.98 FPE: 3.58587e-22
AIC: -49.3799 Det(Omega_mle): 3.09695e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.346441 0.066050 5.245 0.000
L1.Burgenland 0.106247 0.040351 2.633 0.008
L1.Kärnten -0.110452 0.021101 -5.234 0.000
L1.Niederösterreich 0.193953 0.084334 2.300 0.021
L1.Oberösterreich 0.116973 0.083077 1.408 0.159
L1.Salzburg 0.259944 0.042783 6.076 0.000
L1.Steiermark 0.039901 0.056467 0.707 0.480
L1.Tirol 0.103449 0.045571 2.270 0.023
L1.Vorarlberg -0.066919 0.040245 -1.663 0.096
L1.Wien 0.017517 0.073986 0.237 0.813
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.052813 0.141823 0.372 0.710
L1.Burgenland -0.037849 0.086643 -0.437 0.662
L1.Kärnten 0.042070 0.045309 0.929 0.353
L1.Niederösterreich -0.202319 0.181083 -1.117 0.264
L1.Oberösterreich 0.454571 0.178385 2.548 0.011
L1.Salzburg 0.282982 0.091864 3.080 0.002
L1.Steiermark 0.112997 0.121247 0.932 0.351
L1.Tirol 0.305927 0.097851 3.126 0.002
L1.Vorarlberg 0.026750 0.086415 0.310 0.757
L1.Wien -0.029151 0.158864 -0.183 0.854
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.197585 0.033751 5.854 0.000
L1.Burgenland 0.088628 0.020619 4.298 0.000
L1.Kärnten -0.007127 0.010783 -0.661 0.509
L1.Niederösterreich 0.242922 0.043093 5.637 0.000
L1.Oberösterreich 0.159678 0.042451 3.761 0.000
L1.Salzburg 0.040416 0.021861 1.849 0.064
L1.Steiermark 0.027238 0.028854 0.944 0.345
L1.Tirol 0.082192 0.023286 3.530 0.000
L1.Vorarlberg 0.054063 0.020565 2.629 0.009
L1.Wien 0.116436 0.037806 3.080 0.002
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.117968 0.033767 3.494 0.000
L1.Burgenland 0.042400 0.020629 2.055 0.040
L1.Kärnten -0.012922 0.010788 -1.198 0.231
L1.Niederösterreich 0.172604 0.043115 4.003 0.000
L1.Oberösterreich 0.334186 0.042472 7.868 0.000
L1.Salzburg 0.100283 0.021872 4.585 0.000
L1.Steiermark 0.112552 0.028868 3.899 0.000
L1.Tirol 0.089826 0.023298 3.856 0.000
L1.Vorarlberg 0.060551 0.020575 2.943 0.003
L1.Wien -0.017720 0.037825 -0.468 0.639
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.123458 0.063300 1.950 0.051
L1.Burgenland -0.045543 0.038672 -1.178 0.239
L1.Kärnten -0.045270 0.020223 -2.239 0.025
L1.Niederösterreich 0.138530 0.080823 1.714 0.087
L1.Oberösterreich 0.160636 0.079619 2.018 0.044
L1.Salzburg 0.284978 0.041002 6.950 0.000
L1.Steiermark 0.059058 0.054117 1.091 0.275
L1.Tirol 0.158406 0.043674 3.627 0.000
L1.Vorarlberg 0.097501 0.038570 2.528 0.011
L1.Wien 0.071088 0.070906 1.003 0.316
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.074021 0.049438 1.497 0.134
L1.Burgenland 0.024829 0.030203 0.822 0.411
L1.Kärnten 0.053209 0.015794 3.369 0.001
L1.Niederösterreich 0.191680 0.063123 3.037 0.002
L1.Oberösterreich 0.329981 0.062182 5.307 0.000
L1.Salzburg 0.035878 0.032022 1.120 0.263
L1.Steiermark 0.009278 0.042265 0.220 0.826
L1.Tirol 0.120403 0.034109 3.530 0.000
L1.Vorarlberg 0.066072 0.030123 2.193 0.028
L1.Wien 0.096362 0.055378 1.740 0.082
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.172737 0.059584 2.899 0.004
L1.Burgenland 0.005221 0.036401 0.143 0.886
L1.Kärnten -0.065896 0.019036 -3.462 0.001
L1.Niederösterreich -0.106445 0.076078 -1.399 0.162
L1.Oberösterreich 0.206790 0.074944 2.759 0.006
L1.Salzburg 0.054711 0.038595 1.418 0.156
L1.Steiermark 0.247349 0.050939 4.856 0.000
L1.Tirol 0.501510 0.041110 12.199 0.000
L1.Vorarlberg 0.064204 0.036305 1.768 0.077
L1.Wien -0.077422 0.066743 -1.160 0.246
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.160090 0.066086 2.422 0.015
L1.Burgenland -0.002643 0.040374 -0.065 0.948
L1.Kärnten 0.062779 0.021113 2.973 0.003
L1.Niederösterreich 0.168350 0.084380 1.995 0.046
L1.Oberösterreich -0.056856 0.083123 -0.684 0.494
L1.Salzburg 0.208631 0.042806 4.874 0.000
L1.Steiermark 0.139298 0.056498 2.466 0.014
L1.Tirol 0.057042 0.045596 1.251 0.211
L1.Vorarlberg 0.146994 0.040267 3.650 0.000
L1.Wien 0.119278 0.074027 1.611 0.107
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.390524 0.038908 10.037 0.000
L1.Burgenland -0.004567 0.023770 -0.192 0.848
L1.Kärnten -0.020849 0.012430 -1.677 0.093
L1.Niederösterreich 0.202600 0.049678 4.078 0.000
L1.Oberösterreich 0.230420 0.048938 4.708 0.000
L1.Salzburg 0.036762 0.025202 1.459 0.145
L1.Steiermark -0.015803 0.033263 -0.475 0.635
L1.Tirol 0.089078 0.026844 3.318 0.001
L1.Vorarlberg 0.051090 0.023707 2.155 0.031
L1.Wien 0.043775 0.043583 1.004 0.315
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.036405 0.107398 0.170572 0.137712 0.099639 0.080042 0.034234 0.209645
Kärnten 0.036405 1.000000 -0.026589 0.130718 0.048914 0.084912 0.443746 -0.066869 0.089364
Niederösterreich 0.107398 -0.026589 1.000000 0.312747 0.119481 0.273497 0.066637 0.153429 0.292701
Oberösterreich 0.170572 0.130718 0.312747 1.000000 0.212239 0.295607 0.165284 0.136517 0.238469
Salzburg 0.137712 0.048914 0.119481 0.212239 1.000000 0.123003 0.092452 0.104831 0.123907
Steiermark 0.099639 0.084912 0.273497 0.295607 0.123003 1.000000 0.133847 0.107198 0.035757
Tirol 0.080042 0.443746 0.066637 0.165284 0.092452 0.133847 1.000000 0.064178 0.150237
Vorarlberg 0.034234 -0.066869 0.153429 0.136517 0.104831 0.107198 0.064178 1.000000 -0.004385
Wien 0.209645 0.089364 0.292701 0.238469 0.123907 0.035757 0.150237 -0.004385 1.000000